package com.springTest;

import com.pojo.Master;
import jakarta.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring_config.xml")
public class SpringTest1 {
    @Test
    public void test1() {
        //读取配置文件 获取bean
        ApplicationContext ctx2 = new ClassPathXmlApplicationContext("spring_config.xml");
        Master master = (Master) ctx2.getBean("master");
        master.seyHello();
    }
    //加上RunWith和ContextConfiguration注解 省的每次读取配置文件
    @Resource //用注解来进行依赖注入
    private Master master;
    @Test
    public void test2() {
        master.seyHello();
        System.out.println(master);
        master.getPet().shout();
        for (Object o : master.getStringList()) {
            System.out.println(o);
        }
        System.out.println(master.getMap().get("1"));
        System.out.println(master.getMap().get("pet4"));
    }

    @Test
    public void test3() {
        ApplicationContext ctx2 = new ClassPathXmlApplicationContext("spring_config.xml");
        Master master2 = (Master) ctx2.getBean("master2");
        System.out.println(master2);
        master2.getPet().shout();
    }
}
